package com.test.dazuoye.controller;

import com.test.dazuoye.domain.DingDan;
import com.test.dazuoye.domain.shangjia;
import com.test.dazuoye.service.DingDanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @date 2020/6/7-10:18
 */
@Controller
@RequestMapping("/dingdan")
public class DingDanController {

    @Autowired
    private DingDanService dingDanService;

    @RequestMapping("/findDingdan")
    public @ResponseBody List<DingDan> findShangPin() {
        List<DingDan> all = dingDanService.findAll();
        for (DingDan a:all){
            System.out.println(a);
        }
        return all;
    }
    @RequestMapping("/saveDingdan")
    public @ResponseBody
    String saveDingDan(DingDan dingDan) {
        System.out.println(dingDan);
        dingDanService.saveDingDan(dingDan);
        System.out.println("成功");
        return dingDan.getDname();
    }

    @RequestMapping("/deleteDingdan")
    public @ResponseBody void deleteShangPin(String dname) {
        if (dname!=null) {
            dingDanService.deleteDingDan(dname);
            System.out.println("删除成功！"+dname);
        }
        else {
            System.out.println("删除失败");
        }
    }


}
